package com.xinsoft.entity.dto;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.xinsoft.constant.Const;
import com.xinsoft.entity.vo.ErpProductionFeedingVO;
import com.xinsoft.entity.vo.ErpProductionPlanVO;
import com.xinsoft.utils.RedisUtil;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author: π
 * 生产计划 ----对应金蝶的 生产任务单
 * */
@Data
public class KisProductionFeedingDto {

    private String   FInterId;     //主键
    private String  FICMOInterID;       //生产/委外订单号:"
    private String  FOrderEntryID;       //订单行号"
    private String  FBillNo;       //编  号:"
    private String  FItemID;       //产品代码:"
    private Integer  FUnitID;       //单  位:"
    private String  FAuxQty;       //生产数量:"
    private String  FCheckerID;       //审核人:"
    private String  FCheckDate;       //审核日期:"
    private String  FBillerID;       //制单人:"
    private String  FWorkShop;       //生产车间:"
    private String  FType;       //生产类型属性:"
    private String  FOrderInterID;       //销售订单内码:"
    private String  FOrderBillNo;       //销售订单号:"


    private RedisUtil redisUtil = SpringUtil.getBean(RedisUtil.class);
//                    "FInterId":"1003",
//                            "FAuxQty":"24.0000000000",
//                            "FBillerID":"16398",
//                            "FBillNo":"PBOM000003",
//                            "FCheckDate":"2011/10/22 0:00:00",
//                            "FCheckerID":"16398",
//                            "FDate":"2011/10/22 0:00:00",
//                            "FICMOInterID":"1007",
//                            "FItemID":"14536",
//                            "FOrderBillNo":"XD01111001",
//                            "FOrderEntryID":"0",
//                            "FOrderInterID":"1129",
//                            "FPrintCount":"0",
//                            "FType":"1054",
//                            "FUnitID":"188",
//                            "FWorkShop":"14635"
    public  ErpProductionFeedingVO voToPo(KisProductionFeedingDto dto) {
        ErpProductionFeedingVO vo = new ErpProductionFeedingVO();
        vo.setId(new Long(dto.getFInterId()));
        vo.setProductionPlanId(Long.parseLong(dto.getFICMOInterID()));
        vo.setFeedingNo(dto.getFBillNo());
        vo.setSourceId(new Integer((dto.getFOrderInterID())));
        vo.setSourceItemId(new Integer((dto.getFOrderEntryID())));
        vo.setSourceCode(dto.getFOrderBillNo());
        vo.setMaterialId(new Integer((dto.getFItemID())));
        vo.setMaterialId(new Integer((dto.getFItemID())));
        vo.setMainUnitId(dto.getFUnitID());
        vo.setProDept(new Integer((ObjectUtil.isEmpty(dto.getFWorkShop()) ? "0" : dto.getFWorkShop())));
        vo.setPlanCount(new BigDecimal(dto.getFAuxQty()));
        vo.setAuditor(new Integer(dto.getFCheckerID()));
        vo.setCreateBy(Long.parseLong(dto.getFBillerID()));
        vo.setCreateTime((ObjectUtil.isEmpty(dto.getFCheckDate()) ? null : DateUtil.parse(dto.getFCheckDate(),redisUtil.get(Const.TIME_FORMAT).toString())));
        vo.setUpdateBy(Long.parseLong(dto.getFBillerID()));
        vo.setConvCoefficient(new BigDecimal("1"));
        return vo;
    }
}
